var pomelo = require('pomelo'),
    routeUtil = require('./app/util/routeUtil'),
    mongodb = require('mongodb'),
    format = require('util').format,
    app = pomelo.createApp();


app.set('name', 'fight');
app.configure(function()
{
    app.enable('systemMonitor');
});
/*
app.set('serverConfig',
{
	reloadHandlers:true
});

app.set('remoteConfig',
{
	cacheMsg:true,
	interval:30,
	reloadRemotes:true
});
*/

//connector config
app.configure('production|development', 'connector', function()
{
	app.set('connectorConfig',
    {
        connector : pomelo.connectors.hybridconnector,
        heartbeat : 300,
        useDict : true,
        useProtobuf : true
    });
});
//gate config
app.configure('production|development', 'gate', function()
{
    var config =
    {
        connector : pomelo.connectors.hybridconnector,
        useProtobuf : true
    };
	app.set('connectorConfig',config);
});

/*
//player server config
app.configure('production|development', function()
{
	app.route('fight', routeUtil.fight);
	app.filter(pomelo.timeout());
});
*/

//fight server config
app.configure('production|development', function()
{
    app.route('fight', routeUtil.fight);
    app.filter(pomelo.timeout());
});
app.configure
(
    'production|development',
    'connector|fight|player',
    function()
    {
        var server = new mongodb.Server('127.0.0.1',27017,{auto_reconnect:true},100000);
        var db = new mongodb.Db("fight",server); //创建数据库
        db.open(function(err,db)
        {
            if(err)
            {
                throw err;
            }
            else
            {
                db.authenticate('test','test',function(err,res)
                {
                    app.set('dbClient',db);
                })
            }
        });
    }
);

app.start();

process.on
(
    'uncaughtException',
    function(err)
    {
	    console.error('caught exception:',err.stack);
    }
);
